<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        html,
        body {
            height: 100%;
            background-color: #f4f5f6;
        }

        .reqister_box {
            box-sizing: border-box;
            padding: 40px 20px;
        }

        .phone {
            width: 100%;
            height: 43px;
            line-height: 43px;
            border: 1px solid #e8e8e8;
            background-color: #fff;
            box-sizing: border-box;
            padding-left: 50px;
            position: relative;
        }

        .phone input {
            width: 100%;
            height: 43px;
            line-height: 16px;
            outline: none;
            font-size: 14px;
            color: #999;
            box-sizing: border-box;
            padding-left: 10px;
        }

        .num {
            width: 50px;
            height: 43px;
            line-height: 43px;
            text-align: center;
            color: #999;
            font-size: 14px;
            position: absolute;
            left: 0;
            top: 1px;
            background-image: url(../image/my/line.png);
            background-repeat: no-repeat;
            background-size: 1px 14px;
            background-position: right center;
        }

        .next {
            width: 100%;
            height: 43px;
            line-height: 43px;
            text-align: center;
            color: #fff;
            font-size: 14px;
            border-radius: 4px;
            background-color: #999;
            margin: 20px 0;
        }

        .agreement {
            font-size: 12px;
            color: #b4b4b4;
            text-align: center;
        }

        .agreement input {
            width: 12px;
            height: 12px;
            vertical-align: middle;
        }

        .agreement em {
            color: #f85a5a;
        }
    </style>
</head>

<body>
   <div class="reqister_box">
    <div class="phone">
        <input type="text" placeholder="手机号" id="input">
        <div class="num">+86</div>
    </div>
    <div class="next" tapmode onclick="fnNext()">下一步</div>
    <div class="agreement">
        <input type="checkbox" checked="checked"> 同意
        <em tapmode onclick="fnUser_agreement()">今日头条用户协议</em>
    </div>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/SHA1.js"></script>
<script type="text/javascript" src="../script/APICloud-rest.js"></script>
<script type="text/javascript">
    apiready = function() {
      fnReady();
  };
  function fnNext() {
     api.openWin({
        name: 'register_mobile_sumit',
        url: './register_mobile_submit.html',

    });
 }

 function fnLog() {
    api.openWin({
        name: 'login_mobile',
        url: './login_mobile.html',

    });
}

function fnUser_agreement() {
    api.openWin({
        name: './user_agreement',
        url: './user_agreement.html',
    });
}
var username;
var now = Date.now();
var appKey1 = SHA1("A6918573369588" + "UZ" + "20C93719-0DE5-8C9B-2F05-36D9BB835C02" + "UZ" + now) + "." + now;
var appKey = '20C93719-0DE5-8C9B-2F05-36D9BB835C02';

function fnRegister(password) {
 username=$api.byId('input').value;
 var emailText = username,
 passwordText = password;
 api.showProgress({
    title: '注册中',
    modal: true
});
 var body = JSON.stringify({
    username: emailText,
    password: passwordText
});

 api.ajax({
    url: 'https://d.apicloud.com/mcm/api/user',
    method: 'post',
    timeout: 8,
    dataType: 'json',
    returnAll: false,
    "headers": {
        "X-APICloud-AppId": "A6918573369588",
        "X-APICloud-AppKey": appKey1,
        "Content-Type": "application/json"
    },
    "data": {
        body: body
    }
}, function(ret, err) {
    api.hideProgress();
    if (ret) {
        if (ret && ret.id) {
            alert('亲爱的：' +username + ',恭喜你注册成功');
            api.execScript({
                name:'login_mobile',
                frameName: 'login_mobile_frame',
                script:'fnChange('+ret.username+');'
            });
            api.closeWin();
        } else {
            alert('用户名已存在');
        }
    }
});
};
</script>

</html>
